home *** CD-ROM | disk | FTP | other *** search
- /* calc8x8dither.c
- * AUTHOR: Cy Booker, cy@cheepnis.demon.co.uk
- * LICENSE: FreeWare, Copyright (c) 1995 Cy Booker, but see below
- * PURPOSE: convert an 8 bit image to a 16 bit image
- */
-
- #include "calc8x8dither.h"
-
- #include <assert.h>
-
- #include "OS:macros.h"
-
- #include "map16bpp.h"
-
-
-
- /* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- */
-
- #define PROCESS(C1, C2) \
- dist = distance_between_midpoint_16bpp_and_palette_entry(colour, (C1), (C2)); \
- if (dist == 0) { \
- dither[0] = (C1); \
- dither[1] = (C2); \
- return; \
- } \
- if (dist < min_dist) { \
- min_dist = dist; \
- dither[0] = (C1); \
- dither[1] = (C2); \
- }
-
- extern void calculate_8x8dither(
- bits dither[2],
- os_colour colour) {
- bits neighbours[9]; /* entry 8 is the nearest
- * entry (n & 1) is red +/-1
- * entry (n & 2) is green +/-1
- * entry (n & 4) is blue +/-1
- */
- bits closest;
- int i;
- unsigned int dist, min_dist;
- int best[2];
-
- assert(bits);
- neighbours[8] = closest = map_palette_entry_to_16bpp_colour(colour);
- min_dist = ~0u;
- PROCESS(closest, closest);
- for (i= 0; (i < 7); i++) {
- neighbours[i] = map_palette_entry_to_16bpp_colour_offset(colour, i);
- PROCESS(closest, neighbours[i])
- }
- for (i= 0; (i < 7); i++) {
- for (j= i+1; (j < 8); j++) {
- PROCESS(neighbours[i], neighbours[j])
- }
- }
- assert(min_dist != ~0u);
- /*
- * here already set up a closest match
- */
- return;
- }
-